package view
{
	
	import flash.display.*;
	import flash.text.*;
	
	import model.CampPx;
	import manager.ViewMgr;
	import event.Evt;
		
	/**
	 * -- ChooseCampView --
	 * @desc	let user choose a camp
	 * @author	Aqua (built on 2011-11-25)
	 */
	public class ChooseCampView extends BaseView
	{
		//---------------------//
		//     Constructor     //
		//---------------------//
		
		/**************************************************************************
		 * -- ChooseCampView --
		 * @desc		constructor
		 * @param		main view object of this view class
		 *************************************************************************/
		public function ChooseCampView(viewComponent:DisplayObjectContainer):void
		{
			super(viewComponent);
			
			_viewComponent.name = VIEW_NAME;
			_campPx = getPx(CampPx.NAME) as CampPx;
			_campIndex = -1;
			
			addAddCmd("camp",			add_camp);
			addAddCmd("txt_name",		add_txt_name);
			addAddCmd("btn_confirm",	add_btn_confirm);
			addAddCmd("image_camp",		add_image_camp);
			
			addClickCmd("camp",			click_camp);
			addClickCmd("btn_confirm",	click_btn_confirm);
		}
		
		//------------------//
		//     Privates     //
		//------------------//
		
		//-- Add Handlers --//
		private function add_camp():void
		{
			var index:int;
			var mc:MovieClip;
			
			index = getIndex(_display);
			mc = MovieClip(_display);
			mc.mouseChildren = false;
			mc.buttonMode = true;
			mc.gotoAndStop(index == _campIndex ? "over" : "up");
		}
		private function add_txt_name():void
		{
			var index:int;
			var xml:XML;
			
			index = getIndex(_display);
			xml = _campPx.getCampXML(index);
			TextField(_display).text = (xml ? xml.full_name : "");
		}
		private function add_btn_confirm():void
		{
			makeBtn(_display);
		}
		private function add_image_camp():void
		{
			
		}
		
		//-- Click Handlers --//
		private function click_camp():void
		{
			_campIndex = getIndex(_display);
			onRefresh();
		}
		private function click_btn_confirm():void
		{
			if ( -1 != _campIndex)
			{
				_evt.dispatch(Evt.CHOOSE_CAMP);
				_campPx.chooseCamp(_campIndex);
			}
		}
				
		
		public static const VIEW_NAME	:String = "CHOOSE_CAMP_VIEW";
		public static const LAYER_INDEX	:int	= 5;
		
		private var _campPx		:CampPx;
		private var _campIndex	:int;
	}
	
}